﻿namespace ImageProcessing.ImageProcessor
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    /// <summary>
    /// band filter class
    /// </summary>
    public static class IMG_BandFilter
    {
        /// <summary>
        /// IMs the g_ band reject.
        /// </summary>
        /// <param name="img_Original">The img_ original.</param>
        /// <param name="img_D0">The img_ d0.</param>
        /// <param name="band_width">The band_width.</param>
        /// <returns>image edited</returns>
        public static Entities.IMG_Image IMG_BandReject(Entities.IMG_Image img_Original, double img_D0, double band_width)
        {
            try
            {
                int img_Width = img_Original.Width;
                int img_Height = img_Original.Height;
                double u0 = img_Width / 2;
                double v0 = img_Height / 2;
                IMG_FourierClass img_PreNormalization = new IMG_FourierClass(img_Original);
                img_PreNormalization.IMG_CalculateFourier();
                Entities.IMG_Image img_returned = new Entities.IMG_Image(img_Width, img_Height);
                Entities.IMG_Image img_restored = new Entities.IMG_Image(img_Width, img_Height);

                for (int v = 0; v < img_Height; v++)
                {
                    double h = v - v0;
                    for (int u = 0; u < img_Width; u++)
                    {
                        double w = u - u0;
                        double distance = Math.Sqrt((Math.Pow(w, 2) + Math.Pow(h, 2)));
                        if ((distance < img_D0 + (band_width / 2)) && (distance > img_D0 - (band_width / 2)))
                        {
                            img_PreNormalization.RealRed[u, v] = 0;
                            img_PreNormalization.ImagRed[u, v] = 0;
                            img_PreNormalization.RealGreen[u, v] = 0;
                            img_PreNormalization.ImagGreen[u, v] = 0;
                            img_PreNormalization.RealBlue[u, v] = 0;
                            img_PreNormalization.ImagBlue[u, v] = 0;
                        }
                    }
                }

                img_restored = img_PreNormalization.RestoreImage();
                img_returned = IMG_Normalize.IMG_NormalizeImage(img_restored);
                return img_returned;
            }
            catch (Exception img_EX)
            {
                Logger.LogException(img_EX);
                throw;
            }
        }

        /// <summary>
        /// IMs the g_ band pass.
        /// </summary>
        /// <param name="img_Original">The img_ original.</param>
        /// <param name="img_D0">The img_ d0.</param>
        /// <param name="band_width">The band_width.</param>
        /// <returns>edited image</returns>
        public static Entities.IMG_Image IMG_BandPass(Entities.IMG_Image img_Original, double img_D0, double band_width)
        {
            try
            {
                int img_Width = img_Original.Width;
                int img_Height = img_Original.Height;
                double u0 = img_Width / 2;
                double v0 = img_Height / 2;
                IMG_FourierClass img_PreNormalization = new IMG_FourierClass(img_Original);
                img_PreNormalization.IMG_CalculateFourier();
                Entities.IMG_Image img_returned = new Entities.IMG_Image(img_Width, img_Height);
                Entities.IMG_Image img_restored = new Entities.IMG_Image(img_Width, img_Height);

                for (int v = 0; v < img_Height; v++)
                {
                    double h = v - v0;
                    for (int u = 0; u < img_Width; u++)
                    {
                        double w = u - u0;
                        double distance = Math.Sqrt((Math.Pow(w, 2) + Math.Pow(h, 2)));
                        if (distance > img_D0 + (band_width / 2) || distance < img_D0 - (band_width / 2))
                        {
                            img_PreNormalization.RealRed[u, v] = 0;
                            img_PreNormalization.ImagRed[u, v] = 0;
                            img_PreNormalization.RealGreen[u, v] = 0;
                            img_PreNormalization.ImagGreen[u, v] = 0;
                            img_PreNormalization.RealBlue[u, v] = 0;
                            img_PreNormalization.ImagBlue[u, v] = 0;
                        }
                    }
                }

                img_restored = img_PreNormalization.RestoreImage();
                img_returned = IMG_Normalize.IMG_NormalizeImage(img_restored);
                return img_returned;
            }
            catch (Exception img_EX)
            {
                Logger.LogException(img_EX);
                throw;
            }
        }
    }
}
